// 导入 express
const express = require("express");
// 导入上传图片
const multer = require("multer");
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, "uploads/phone-simple");
  },
  filename: function (req, file, cb) {
    cb(null, file.originalname);
  },
});
const upload = multer({ storage: storage });
// 创建路由对象
const router = express.Router();

// 导入手机信息模块
const brand_info = require("../router-handler/brand");

// 上传手机图片
router.post(
  "/addPhonePic",
  upload.single("phone-pic"),
  brand_info.uploadPhonePic
);

// 上传手机信息
router.post("/addPhone", multer().none(), brand_info.addPhone);

// 按名字(phone_name)删除资料
router.post("/delPhone", multer().none(), brand_info.delPhone);

// 获取品牌的基本信息
router.get("/brandInfo", brand_info.getbrandInfo);

// 获取手机的基本参数
router.get("/phoneInfo", brand_info.getphoneInfo);

// 模糊查询手机
router.get("/fuzzy", brand_info.fuzzyGetName);

// 获取从高到低排序的前二十台手机(条件从前端接收)
router.get("/getphoneRank", brand_info.getphoneRank);

// 向外共享路由对象
module.exports = router;
